import axios from './interceptor'

// let prefixUrl = 'http://192.168.1.201:8084';
let prefixUrl = 'http://localhost:8084';


export function getPrefixUrl() {
  return prefixUrl
}

/**
 * 普通post
 * @param url
 * @param params
 * @returns {Promise<any>}
 */
export function post(url, params) {
  return new Promise((resolve, reject) => {
    axios({
      url: prefixUrl + url,
      method: 'post',
      params: params
    }).then(response => {
      resolve(response)
    }).catch(error => {
      reject(error)
    })
  })
}

/**
 * post, 参数在requestBody中
 * @param url
 * @param params
 * @returns {Promise<any>}
 */
export function postBody(url, params) {
  return new Promise((resolve, reject) => {
    axios({
      url: prefixUrl + url,
      method: 'post',
      data:params
    }).then(response => {
      resolve(response)
    }).catch(error => {
      reject(error)
    })
  })
}

/**
 * get请求
 * @param url
 * @param params
 * @returns {Promise<any>}
 */
export function get(url, params) {
  return new Promise((resolve, reject) => {
    axios({
      url: prefixUrl + url,
      method: 'get',
      params:params
    }).then(response => {
      resolve(response)
    }).catch(error => {
      reject(error)
    })
  })
}

/**
 * 通过Post方法
 * @param url
 * @param param
 * @returns {Promise<void>}
 */
export async function synPost(url, params) {
  let res = await axios({
    url: prefixUrl + url,
    method: 'post',
    params: params
  })
  return res;
}

/**
 * 获取postbody 的同步数据
 * @param url
 * @param params
 * @returns {Promise<void>}
 */
export async function synPostBody(url, params) {
  let res = await axios({
    url: prefixUrl + url,
    method: 'post',
    data:params
  })
  return res;
}

/**
 * 获取get同步数据
 * @param url
 * @param params
 * @returns {Promise<void>}
 */
export async function synGet(url, params) {
  let res = await axios({
    url: prefixUrl + url,
    method: 'get',
    params:params
  })
  return res;
}
